package front

import (
	resFront "hft/Http/Models/request/front"
	utils "hft/Http/Utils"

	"gorm.io/gorm"
)

type Active struct{}

func (a *Active) List(paginate *resFront.ActivePage, types []int, region_link string) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		return db.Scopes(a.Type(types, db)).Where("region_link LIKE ?", region_link).Preload("Cont").Scopes(a.Lou(paginate.LouPanId, db)).Order("create_time desc").Scopes(utils.Paginate(paginate.Page, db))
	}
}

func (a *Active) Lou(louId int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if louId == 0 {
			return db
		} else {
			return db.Where("lou_pan_id = ?", louId)
		}
	}
}

func (a *Active) Type(types []int, db *gorm.DB) func(db *gorm.DB) *gorm.DB {
	return func(db *gorm.DB) *gorm.DB {
		if len(types) == 0 {
			return db
		} else {
			return db.Where("active_group IN ?", types)
		}
	}
}

var ActiveDao = new(Active)
